<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>手写数字识别训练平台</title>
    <link href="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.0/css/bootstrap.min.css" rel="stylesheet">
    <link href="https://cdn.bootcdn.net/ajax/libs/font-awesome/6.4.0/css/all.min.css" rel="stylesheet">
    <link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">
</head>
<body>
    <div class="container-fluid">
        <div class="row">
            <!-- 左侧控制面板 -->
            <div class="col-md-3 bg-light p-4">
                <h3 class="mb-4">
                    <i class="fas fa-brain"></i> 训练控制
                </h3>
                
                <div class="mb-3">
                    <label class="form-label">输入数字标签 (0-9):</label>
                    <input type="number" id="digitLabel" class="form-control" min="0" max="9" value="0">
                </div>
                
                <button class="btn btn-primary w-100 mb-2" onclick="trainModel()">
                    <i class="fas fa-graduation-cap"></i> 训练模型
                </button>
                
                <button class="btn btn-success w-100 mb-2" onclick="predictDigit()">
                    <i class="fas fa-magic"></i> 识别数字
                </button>
                
                <button class="btn btn-warning w-100 mb-2" onclick="clearCanvas()">
                    <i class="fas fa-eraser"></i> 清空画布
                </button>
                
                <button class="btn btn-danger w-100 mb-4" onclick="resetModel()">
                    <i class="fas fa-redo"></i> 重置模型
                </button>
                
                <!-- 训练状态 -->
                <div class="card">
                    <div class="card-header">
                        <h6 class="mb-0">训练状态</h6>
                    </div>
                    <div class="card-body">
                        <p class="mb-1">已训练样本: <span id="sampleCount">0</span></p>
                        <div class="progress mb-2">
                            <div id="progressBar" class="progress-bar" style="width: 0%"></div>
                        </div>
                        <p class="mb-1">准确率: <span id="accuracy">-</span></p>
                        <small id="statusMessage" class="text-muted">等待训练数据...</small>
                    </div>
                </div>
            </div>
            
            <!-- 右侧画布区域 -->
            <div class="col-md-9 p-4">
                <h2 class="mb-4">手写数字识别训练平台</h2>
                
                <div class="row">
                    <div class="col-md-8">
                        <div class="canvas-container">
                            <canvas id="drawingCanvas" width="280" height="280"></canvas>
                            <div class="canvas-overlay">
                                <small class="text-muted">在上方区域手写数字</small>
                            </div>
                        </div>
                    </div>
                    
                    <div class="col-md-4">
                        <div class="result-container">
                            <h5>识别结果</h5>
                            <div class="result-display">
                                <div class="digit-result">
                                    <span id="predictedDigit" class="digit-number">?</span>
                                </div>
                                <div class="confidence-bar">
                                    <small>置信度</small>
                                    <div class="progress">
                                        <div id="confidenceBar" class="progress-bar bg-success" style="width: 0%"></div>
                                    </div>
                                    <small id="confidenceText">0%</small>
                                </div>
                            </div>
                            
                            <h6 class="mt-4">概率分布</h6>
                            <div id="probabilityChart">
                                <!-- 概率条将在这里动态生成 -->
                            </div>
                        </div>
                    </div>
                </div>
                
                <div class="row mt-4">
                    <div class="col-12">
                        <div class="alert alert-info">
                            <h6>使用说明:</h6>
                            <ol class="mb-0">
                                <li>在画布上手写一个数字 (0-9)</li>
                                <li>在左侧输入正确的数字标签</li>
                                <li>点击"训练模型"将样本加入训练集</li>
                                <li>收集至少5个样本后，模型会自动训练</li>
                                <li>训练完成后，可以手写新数字并点击"识别数字"</li>
                            </ol>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <script src="https://cdn.bootcdn.net/ajax/libs/bootstrap/5.3.0/js/bootstrap.bundle.min.js"></script>
    <script src="{{ url_for('static', filename='js/app.js') }}"></script>
</body>
</html>
